unit u_gamemenu;

interface

uses
system.Drawing,
u_animsprite,
sysutils,
u_font,
system.windows.Forms,
Microsoft.DirectX,
Microsoft.DirectX.Direct3D,
Microsoft.DirectX.Direct3DX;

type

  c_gamemenu = class

    private

    const
       resol : Array [0..5] of string = ('800 / 600',  '1024 / 768', '1280 / 800', '1280 / 960', '1680 / 1050', 'Maximisé');
       fog_val : Array [0..4]  of string = ('10', '15', '20', '30', '40');

    var
    visible : boolean;
    opt_bool: boolean;
    opt_est_dehors: boolean;
    continuer: c_animsprite;
    quitter: c_animsprite;
    menu: c_animsprite;
    option: c_animsprite;
    resolution: c_animsprite;
    resolutiontext: c_animsprite;
    son: c_animsprite;
    sonoui: c_animsprite;
    resolutiondroit: c_animsprite;
    resolutiongauche: c_animsprite;
    sonnon: c_animsprite;
    fog: c_animsprite;
    fogtext: c_animsprite;
    fogdroit: c_animsprite;
    foggauche: c_animsprite;
    ok: c_animsprite;
    annuler: c_animsprite;
    apply: c_animsprite;



    fond: texture;
    _sprite: sprite;
    text_resol : u_text;
    text_fog : u_text;
    num_resol : integer;
    num_fog : integer;
    goto_menu: boolean;


    public
    dist_fog : integer;
    constructor create(dev : Device; height, width: integer);
    procedure affi_menu(mousex, mousey, width, height: integer);
    procedure sur_bouton(mousex, mousey, width, height: integer);
    procedure onresize(width, height: integer);
    procedure is_visible(bool: boolean);
    function _visible: boolean;
    procedure onclick(mousex, mousey, width, height: integer);
    procedure gest_option(mouse_x, mouse_y, width, height: integer);
    procedure affi_option;
    procedure faire_ven_op;

  end;

implementation

uses
  u_engine;

  function c_gamemenu._visible;
  begin
    result := visible;
  end;

  constructor c_gamemenu.create;
    begin
      inherited create;
        continuer := c_animsprite.create(dev, 'asus menu\menu_princ\continuer.png', 'asus menu\menu_princ\continuer_s.png', height div 5 - 15, width div 2 - 137);
        continuer.set_pas(300);
        quitter := c_animsprite.create(dev, 'asus menu\menu_princ\quitter.png', 'asus menu\menu_princ\quitter1.png', 4 * height div 5 - 15, width div 2 - 137);
        quitter.set_pas(300);
        option := c_animsprite.create(dev, 'asus menu\menu_princ\options.png', 'asus menu\menu_princ\options1.png', 2 * height div 5 - 15, width div 2 - 137);
        option.set_pas(300);
        menu := c_animsprite.create(dev, 'asus menu\menu_princ\menu princ.png', 'asus menu\menu_princ\menu princ_s.png', 3 * height div 5 - 15, width div 2 - 137);
        menu.set_pas(300);



        resolution := c_animsprite.create(dev, 'asus menu\menu_princ\resolution.png', 'asus menu\menu_princ\resolution1.png', height div 5 - 35, width div 2 - 137);
        resolutiontext := c_animsprite.create(dev, 'asus menu\menu_princ\barratexte.png', 'asus menu\menu_princ\barratexte1.png', height div 5, width div 2 - 107);
        resolutiondroit := c_animsprite.create(dev, 'asus menu\menu_princ\next.png', 'asus menu\menu_princ\next1.png', height div 5, width div 2 + 110);
        resolutiongauche := c_animsprite.create(dev, 'asus menu\menu_princ\prec.png', 'asus menu\menu_princ\prec1.png', height div 5, width div 2 - 140);
        son := c_animsprite.create(dev, 'asus menu\menu_princ\son.png', 'asus menu\menu_princ\son1.png', 2 * height div 5 - 35, width div 2 - 137);
        sonoui := c_animsprite.create(dev, 'asus menu\menu_princ\oui.png', 'asus menu\menu_princ\oui1.png', 2 * height div 5, width div 2 - 140);
        sonnon := c_animsprite.create(dev, 'asus menu\menu_princ\non.png', 'asus menu\menu_princ\non1.png', 2 * height div 5, width div 2 + 5);

        fog := c_animsprite.create(dev, 'asus menu\menu_princ\brouillard.png', 'asus menu\menu_princ\brouillard1.png', 3 * height div 5 - 35, width div 2 - 137);
        fogtext := c_animsprite.create(dev, 'asus menu\menu_princ\barratexte.png', 'asus menu\menu_princ\barratexte1.png', 3 * height div 5, width div 2 - 107);
        fogdroit := c_animsprite.create(dev, 'asus menu\menu_princ\next.png', 'asus menu\menu_princ\next1.png', 3 * height div 5, width div 2 + 110);
        foggauche := c_animsprite.create(dev, 'asus menu\menu_princ\prec.png', 'asus menu\menu_princ\prec1.png', 3 * height div 5, width div 2 - 140);


        ok := c_animsprite.create(dev, 'asus menu\menu_princ\ok.png', 'asus menu\menu_princ\ok1.png', 4 * height div 5 - 50, width div 2 - 68);
        annuler := c_animsprite.create(dev, 'asus menu\menu_princ\annuler.png', 'asus menu\menu_princ\annuler1.png', 4 * height div 5 - 15, width div 2 - 68);
        apply := c_animsprite.create(dev, 'asus menu\menu_princ\appliquer.png', 'asus menu\menu_princ\appliquer1.png', 4 * height div 5 + 20, width div 2 - 68);

        text_resol := u_text.create(dev, 14, color.Blue, resol[0], 'Comic Sans MS', FontStyle.Regular);
        text_resol.set_visible(false);
        text_fog := u_text.create(dev, 14, color.Blue, fog_val[0], 'Comic Sans MS', fontstyle.regular);
        text_fog.set_visible(false);
        _sprite := sprite.create(dev);
        fond := TextureLoader.FromFile(dev, 'asus menu\menu_princ\fond.png');
        visible := false;
        opt_bool := false;
        opt_est_dehors := true;
        goto_menu := false;
    end;

  procedure c_gamemenu.affi_menu;
  begin
    if visible then
      begin
        _sprite.&Begin(SpriteFlags.AlphaBlend);
          _sprite.Draw(fond, Vector3.Create(0, 0 ,0), Vector3.Create(0, 0 ,0), color.White.ToArgb);
        _sprite.&End;
        if not opt_bool then
          begin
            if option.est_dehors then
              begin
                if goto_menu <> opt_bool then
                  begin
                     opt_bool := goto_menu;
                  end
                else
                  begin
                    option.faire_venir;
                    menu.faire_venir;
                    continuer.faire_venir;
                    quitter.faire_venir;
                  end;
              end;
              option.render;
              menu.render;
              continuer.render;
              quitter.render;
          end
         else
           begin
             if resolution.est_dehors then
              begin
                if goto_menu <> opt_bool then
                  begin
                    opt_bool := goto_menu;
                  end
                else
                  begin
                    faire_ven_op;
                  end;
              end;
              affi_option;
           end;
      end;

  end;

  procedure c_gamemenu.sur_bouton;
  begin
    if not opt_bool then
      begin
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= height div 5 - 15 - 10) and (mousey <= height div 5 - 15 + 30 - 10)  then
            begin
             if continuer.est_dedans then
               continuer.pause;
            end
        else
          continuer.play;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 2 * height div 5 - 15 - 10) and (mousey <= 2 * height div 5 - 15 + 30 - 10)  then
            begin
             if option.est_dedans then
               option.pause;
            end
        else
          option.play;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 3 * height div 5 - 15 - 10) and (mousey <= 3 * height div 5 - 15 + 30 - 10)  then
            begin
             if menu.est_dedans then
               menu.pause;
            end
        else
          menu.play;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 4 * height div 5 - 15 - 10) and (mousey <= 4 * height div 5 - 15 + 30 - 10)  then
            begin
             if quitter.est_dedans then
               quitter.pause;
            end
        else
          quitter.play
      end
    else
      begin
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= height div 5 - 35 - 10) and (mousey <= height div 5 - 35 + 30 - 10)  then
            begin
             if resolution.est_dedans then
               resolution.pause;
            end
        else
          resolution.play;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 2 * height div 5 - 35 - 10) and (mousey <= 2 * height div 5 - 35 + 30 - 10)  then
            begin
             if son.est_dedans then
               son.pause;
            end
        else
          son.play;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 3 * height div 5 - 35 - 10) and (mousey <= 3 * height div 5 - 35 + 30 - 10)  then
            begin
             if fog.est_dedans then
               fog.pause;
            end
        else
          fog.play;
        if (mousex >= width div 2 + 110 - 10) and (mousex <= width div 2 + 110 + 30 - 10) and
           (mousey >= 3 * height div 5 - 10) and (mousey <= 3 * height div 5 + 30 - 10)  then
            begin
             if fogdroit.est_dedans then
               fogdroit.pause;
            end
        else
          fogdroit.play; //
        if (mousex >= width div 2 - 140 - 10) and (mousex <= width div 2 - 140 + 30 - 10) and
           (mousey >= 3 * height div 5 - 10) and (mousey <= 3 * height div 5 + 30 - 10)  then
            begin
             if foggauche.est_dedans then
               foggauche.pause;
            end
        else
          foggauche.play;
        if (mousex >= width div 2 + 110 - 10) and (mousex <= width div 2 + 110 + 30 - 10) and
           (mousey >= height div 5 - 10) and (mousey <= height div 5 + 30 - 10)  then
            begin
             if resolutiondroit.est_dedans then
               resolutiondroit.pause;
            end
        else
          resolutiondroit.play;
        if (mousex >= width div 2 - 140 - 10) and (mousex <= width div 2 - 140 + 30 - 10) and
           (mousey >= height div 5 - 10) and (mousey <= height div 5 + 30 - 10)  then
            begin
             if resolutiongauche.est_dedans then
               resolutiongauche.pause;
            end
        else
          resolutiongauche.play;
        if (mousex >= width div 2 - 107 - 10) and (mousex <= width div 2 - 107 + 215 - 10) and
           (mousey >= height div 5 - 10) and (mousey <= height div 5 + 30 - 10)  then
            begin
             if resolutiontext.est_dedans then
               resolutiontext.pause;
            end
        else
          resolutiontext.play;
        if (mousex >= width div 2 - 107 - 10) and (mousex <= width div 2 - 107 + 215 - 10) and
           (mousey >= 3 * height div 5 - 10) and (mousey <= 3 * height div 5 + 30 - 10)  then
            begin
             if fogtext.est_dedans then
               fogtext.pause;
            end
        else
          fogtext.play;
        if (mousex >= width div 2 - 140 - 10) and (mousex <= width div 2 - 140 + 137 - 10) and
           (mousey >= 2 * height div 5 - 10) and (mousey <= 2 * height div 5 + 30 - 10)  then
            begin
             if sonoui.est_dedans then
               sonoui.pause;
            end
        else
          sonoui.play;
        if (mousex >= width div 2 + 5 - 10) and (mousex <= width div 2 + 5 + 137 - 10) and
           (mousey >= 2 * height div 5 - 10) and (mousey <= 2 * height div 5 + 30 - 10)  then
            begin
             if sonnon.est_dedans then
               sonnon.pause;
            end
        else
          sonnon.play;
        if (mousex >= width div 2 - 68 - 10) and (mousex <= width div 2 - 68 + 137 - 10) and
           (mousey >= 4 * height div 5 + 20 - 10) and (mousey <= 4 * height div 5 + 20 + 30 - 10)  then
            begin
             if apply.est_dedans then
               apply.pause;
            end
        else
          apply.play;
        if (mousex >= width div 2 - 68 - 10) and (mousex <= width div 2 - 68 + 137 - 10) and
           (mousey >= 4 * height div 5 - 50 - 10) and (mousey <= 4 * height div 5 - 50 + 30 - 10)  then
            begin
             if ok.est_dedans then
               ok.pause;
            end
        else
          ok.play;
        if (mousex >= width div 2 - 68 - 10) and (mousex <= width div 2 - 68 + 137 - 10) and
           (mousey >= 4 * height div 5 - 15 - 10) and (mousey <= 4 * height div 5 - 15 + 30 - 10)  then
            begin
             if annuler.est_dedans then
               annuler.pause;
            end
        else
          annuler.play;


      end;
  end;

  procedure c_gamemenu.faire_ven_op;
  begin
      resolution.faire_venir;
      resolutiontext.faire_venir;
      resolutiondroit.faire_venir;
      resolutiongauche.faire_venir;
      son.faire_venir;
      sonnon.faire_venir;
      sonoui.faire_venir;
      fog.faire_venir;
      fogtext.faire_venir;
      fogdroit.faire_venir;
      foggauche.faire_venir;
      foggauche.faire_venir;
      ok.faire_venir;
      annuler.faire_venir;
      apply.faire_venir;
      opt_est_dehors := false;
  end;

  procedure c_gamemenu.affi_option;
  var
    caca: boolean;
    begin
      resolution.render;
      resolutiontext.render;
      resolutiondroit.render;
      resolutiongauche.render;
      son.render;
      sonnon.render;
      sonoui.render;
      fog.render;
      fogtext.render;
      fogdroit.render;
      foggauche.render;
      foggauche.render;
      ok.render;
      annuler.render;
      apply.render;
      if resolution.est_dedans then
        begin
          text_resol.set_visible(true);
          text_fog.set_visible(true);
          text_resol.text_render;
          text_fog.text_render;
        end
      else
        begin
          text_resol.set_visible(false);
          text_fog.set_visible(false);
        end;

    end;


  procedure c_gamemenu.onresize(width: Integer; height: Integer);
  begin

    text_fog.set_coord(trunc(width div 2 - 100), trunc(3 * height div 5 - 5));
    text_resol.set_coord(trunc(width div 2 - 100), trunc(height div 5 - 5));
    continuer.change_resolution(width, height, width div 2 - 137, height div 5 - 15);
    option.change_resolution(width, height,  width div 2 - 137, 2 * height div 5 - 15);
    menu.change_resolution(width, height,  width div 2 - 137, 3 * height div 5 - 15);
    quitter.change_resolution(width, height, width div 2 - 137, 4 * height div 5 - 15);

    resolution.change_resolution(width, height, width div 2 - 137, height div 5 - 35);
    resolutiontext.change_resolution(width, height, width div 2 - 107, height div 5);
    son.change_resolution(width, height, width div 2 - 137, 2 * height div 5 - 35);
    sonoui.change_resolution(width, height, width div 2 - 140, 2 * height div 5);
    sonnon.change_resolution(width, height, width div 2 + 5, 2 * height div 5);
    fog.change_resolution(width, height, width div 2 - 137, 3 * height div 5 - 35);
    fogtext.change_resolution(width, height, width div 2 - 107, 3 * height div 5);
    fogdroit.change_resolution(width, height, width div 2 + 110, 3 * height div 5);
    foggauche.change_resolution(width, height, width div 2 - 140, 3 * height div 5);

    resolutiondroit.change_resolution(width, height, width div 2 + 110, height div 5);
    resolutiongauche.change_resolution(width, height, width div 2 - 140, height div 5);

    ok.change_resolution(width, height, width div 2 - 68, 4 * height div 5 - 50);
    annuler.change_resolution(width, height, width div 2 - 68, 4 * height div 5 - 15);
    apply.change_resolution(width, height, width div 2 - 68, 4 * height div 5 + 20);

    if opt_bool then
      begin
        continuer.set_out;
        menu.set_out;
        option.set_out;
        quitter.set_out;
      end;

    if not opt_bool then
      begin
        resolution.set_out;
        resolutiontext.set_out;
        son.set_out;
        sonoui.set_out;
        sonnon.set_out;
        fog.set_out;
        fogtext.set_out;
        fogdroit.set_out;
        foggauche.set_out;
        resolutiondroit.set_out;
        resolutiongauche.set_out;
        ok.set_out;
        annuler.set_out;
        apply.set_out;
      end;

  end;

  procedure c_gamemenu.is_visible(bool: Boolean);
  begin
    visible := bool;
  end;

  procedure c_gamemenu.onclick;
  begin
    if visible and (not opt_bool) then
      begin
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= height div 5 - 15 - 10) and (mousey <= height div 5 - 15 + 30 - 10)  then
            visible := false;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 2 * height div 5 - 15 - 10) and (mousey <= 2 * height div 5 - 15 + 30 - 10)  then
            begin
              goto_menu := not opt_bool;
              menu.faire_sortir;
              option.faire_sortir;
              continuer.faire_sortir;
              quitter.faire_sortir;
            end;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 3 * height div 5 - 15 - 10) and (mousey <= 3 * height div 5 - 15 + 30 - 10)  then
            begin
              mymenu.montre_menu;
              visible := false;
            end;
        if (mousex >= width div 2 - 137 - 10) and (mousex <= width div 2 - 137 + 275 - 10) and
           (mousey >= 4 * height div 5 - 15 - 10) and (mousey <= 4 * height div 5 - 15 + 30 - 10)  then
            begin
              application.exit;
            end;
      end
    else
      if visible and opt_bool then
        gest_option(mousex, mousey, width, height);
  end;


  procedure c_gamemenu.gest_option;
  begin


    if (mouse_x > width div 2 + 110) and (mouse_x < width div 2 + 140)
      and (mouse_y > height div 5) and (mouse_y < height div 5 + 30) then
        begin
          num_resol := num_resol + 1;
          if num_resol > High(resol) then
            num_resol := High(resol);
          text_resol.change_text(Resol[num_resol]);
        end
    else
      if (mouse_x > width div 2 - 140) and (mouse_x < width div 2 - 110)
          and (mouse_y > height div 5) and (mouse_y < height div 5 + 30) then
            begin
              num_resol := num_resol - 1;
              if num_resol < Low(resol) then
                num_resol := Low(resol);
              text_resol.change_text(Resol[num_resol]);

            end
        else
          if (mouse_x > width div 2 + 110) and (mouse_x < width div 2 + 140)
            and (mouse_y > 3 * height div 5) and (mouse_y < 3 * height div 5 + 30) then
              begin
                num_fog := num_fog + 1;
                if num_fog > High(fog_val) then
                  num_fog := High(fog_val);
                text_fog.change_text(fog_val[num_fog]);
                dist_fog := StrToInt(fog_val[num_fog]);

              end
            else
              if (mouse_x > width div 2 - 140) and (mouse_x < width div 2 - 110)
                and (mouse_y > 3 * height div 5) and (mouse_y < 3 * height div 5 + 30) then
                  begin
                    num_fog := num_fog - 1;
                    if num_fog < Low(fog_val) then
                      num_fog := Low(fog_val);
                    text_fog.change_text(fog_val[num_fog]);
                    dist_fog := StrToInt(fog_val[num_fog]);

                  end
                else
                  if (mouse_x > width div 2 - 68) and (mouse_x < width div 2 + 68)
                    and (mouse_y > 4 * height div 5 - 50) and (mouse_y < 4 * height div 5 - 20) then
                      begin
                        resolution.faire_sortir;
                        case num_resol of
                          0 : begin
                                myform.change_size(800, 600);
                                myform.set_max(false);
                          end;
                          1 : begin;
                                myform.change_size(1024, 768);
                                myform.set_max(false);
                          end;
                          2 : begin
                                myform.change_size(1280, 800);
                                myform.set_max(false);
                          end;
                          3 : begin
                                myform.change_size(1280, 960);
                                myform.set_max(false);
                          end;
                          4 : begin
                                myform.change_size(1680, 1050);
                                myform.set_max(false);
                          end;
                          5 : begin
                                myform.set_max(true);
                          end;
                        end;

                      end
                    else
                      if (mouse_x > width div 2 - 68) and (mouse_x < width div 2 + 68)
                        and (mouse_y > 4 * height div 5 - 15) and (mouse_y < 4 * height div 5 + 15) then
                          begin
                            resolution.faire_sortir;
                          end
                        else
                          if (mouse_x > width div 2 - 68) and (mouse_x < width div 2 + 68)
                            and (mouse_y > 4 * height div 5 + 20) and (mouse_y < 4 * height div 5 + 50) then
                              begin
                                case num_resol of
                                  0 : begin
                                        myform.change_size(800, 600);
                                        myform.set_max(false);
                                  end;
                                  1 : begin;
                                        myform.change_size(1024, 768);
                                        myform.set_max(false);
                                  end;
                                  2 : begin
                                        myform.change_size(1280, 800);
                                        myform.set_max(false);
                                  end;
                                  3 : begin
                                        myform.change_size(1280, 960);
                                        myform.set_max(false);
                                  end;
                                  4 : begin
                                        myform.change_size(1680, 1050);
                                        myform.set_max(false);
                                  end;
                                  5 : begin
                                        myform.set_max(True);
                                  end;
                                      end;
                              end;
  end;




end.
